Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hash-through

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hash-through

a PassThrough stream that taps to chunks flow and calculates the digest on the fly

  • 0.1.16
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

hash-through

A PassThrough stream that taps to chunks flow and calculates the digest on the fly.

The hashing function has to be supplied. It should be in a form similar to createHash from node crypto module.

Setup

npm install hash-through

Usage

A short example using createHash from node's crypto module:

const HashThrough = require('hash-through')
const crypto = require('crypto')

function createHash(){
  // here we are wrapping a particular implementation
  return crypto.createHash('sha256')
}

const ht = HashThrough(createHash)

// Now we can pipe through and get the digest ready
// by the very time the streaming is over:

const fs = require('fs')
const src = fs.createReadStream(__filename)

src.pipe(ht).pipe(process.stdout)

ht.on('finish', ()=>{
  console.log(ht.digest('hex'))
})

Basically, createHash should be a function with no args that returns a hash object, which in turn should have two methods: hash.update(chunk) and hash.digest(format) with the same meaning as in crypto module

More examples

The test directory contains some more examples of how to plug in different hash algorithms, including both cryptographic functions from node crypto module:

  • sha256
  • sha512
  • ripemd160

as well as some non-cryptographic ones:

Dependencies

For "a stable streams base, regardless of what version of Node you are using" we use readable-stream standalone stream module instead of Node core implementation (read elaboration on this here).

The idea

The point of this module is that original stream can really pass through the hashing instance 'untouched', so it really is a PassThrough stream from external point of view. One can insert one or more instances of it at any points of piping chains without violating the existing streaming logics. Kind of like tapping to the wire or playing man-in-the-middle.

Keywords

FAQs

Package last updated on 10 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc